<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html class="win-frame">
<head>
<title>${name_china}管理-新建${name_china}</title>
 <%@include file="/common/head.jsp" %>
 
</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
            <span class="split"></span>
            <span>新建${name_china}</span>
        </div>
        <a id="goBack" class="btn-return distance-left" href="javascript:;"><i class="icon icon-arrow-left"></i>返回上级</a>
    </div>
    <div class="page-title-border"></div>
</div>

<form id="addForm" method="post">
  <div id="left" style="width:80%;float:left">
	 <div class="form-wrapper">
		<div class="h4 distance-double">
	        <span class="h4-title"><i class="icon icon-setting"></i>基本信息</span>
	        <span class="h4-border"></span>
	    </div>
	    
	     <div class="form-cont">
	        <p class="form-cont-title">排序号</p>
	        <input type="text" id="reorder" name="reorder" class="summer-input summer-validatebox"  data-validatebox="validType:['noNegativeNumber']"/> 
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title"><span class="field-required">*</span>是否可见</p>
	        <input type="text" id="isVisible" name="isVisible" class="summer-input summer-validatebox"  data-validatebox="validType:['maxLength[10]']"/> 
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title"><span class="field-required">*</span>活动类型</p>
	        <input type="text" id="type" name="type" class="summer-input summer-validatebox"  data-validatebox="validType:['required','maxLength[10]']"/> 
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title"><span class="field-required">*</span>名称</p>
	        <input type="text" id="name" name="name" class="summer-input summer-validatebox"  data-validatebox="validType:['required','maxLength[50]']"/> 
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title"><!-- <span class="field-required">*</span> -->大标题</p>
	        <input type="text" id="topTitle" name="topTitle" class="summer-input summer-validatebox"  data-validatebox="validType:['maxLength[50]']"/> 
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title"><!-- <span class="field-required">*</span> -->副标题</p>
	        <input type="text" id="subTitle" name="subTitle" class="summer-input summer-validatebox"  data-validatebox="validType:['maxLength[50]']"/> 
	     </div>
	     
	      <div class="form-cont">
	        <p class="form-cont-title">活动图片</p>
	        <input type="hidden" id="img" name="img"/>
	        <p style="color:red">建议高：188px；宽：375px</p> 
	     </div>
	     
	     
	     <div class="form-cont">
	        <p class="form-cont-title">活动图片进去的轮播图</p>
	        <input type="hidden" id="banner" name="banner"/>
	        <p style="color:red">建议高：188px；宽：375px</p> 
	     </div>
	   
	     
	     <div id="happ" class="form-cont">
	        <p class="form-cont-title"><span class="field-required">*</span>H5或APP</p>
	        <input type="text" id="linkType" name="linkType" class="summer-input summer-validatebox"  data-validatebox="validType:['required','maxLength[10]']"/> 
	     </div>
	     
	      <!--  <div class="form-cont">
	        <p class="form-cont-title"><span class="field-required">*</span>图片的H5地址或APP标识</p>
	        <input type="text" id="value" name="value" class="summer-input summer-validatebox"  data-validatebox="validType:['required','maxLength[100]']"/> 
	     </div> -->
	     <div class="form-cont">
	        <p class="form-cont-title"><!-- <span class="field-required">*</span> -->活动说明</p>
	        <textarea type="text" id="activityDesc" name="activityDesc" class="summer-textarea summer-validatebox"  data-validatebox="validType:['maxLength[3000]']"/></textarea>
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title">备注</p>
	        <textarea class="summer-textarea" id="note" name="note"></textarea>
	     </div>
	     
	     <div class="form-cont" >
	         <p class="form-cont-title">商品选择</p>
		     <span class="field-cont">
		        <span class="field-cont-title">商品名称</span>
		        <input type="text" class="summer-input" id="goodsName"/>
		    </span>
		    <span class="field-cont">
		        <span class="field-cont-title">商品类型</span>
		        <input type="text" class="summer-input" id="spuPlatform"/>
		    </span>
		     <span class="field-cont">
		        <span class="field-cont-title">商品分类</span>
		        <input type="text" id="categoryId" name="categoryId" />  
		    </span>
		     <span class="field-cont">
		        <span class="field-cont-title">是否爆款</span>
		        <input type="text" class="summer-input" id="isHot"/>
		    </span>
		    <span class="field-cont">
		        <span class="field-cont-title">是否精品</span>
		        <input type="text" class="summer-input" id="isJingping" />
		    </span>
		     <span class="field-cont">
		        <span class="field-cont-title">佣金排序</span>
		        <input type="text" class="summer-input" id="wlCommission"/>
		    </span>
		     <span class="field-cont">
		        <span class="field-cont-title">佣金比例排序</span>
		        <input type="text" class="summer-input" id="wlCommissionShare"/>
		    </span>
		     <span class="field-cont">
		        <span class="field-cont-title">时间</span>
		        <input type="text" class="summer-input" id="createTime"/>
		    </span>
		      <span class="field-btn-wrapper">
		        <a id="search" class="btn btn-primary btn-icon wave distance-right"><i class="icon icon-search"></i></a>
		        <a id="reset" class="btn btn-icon wave wave-dark"><i class="icon icon-refresh"></i></a>
		    </span>
	     </div>
	     
	      <input id="spuIds" type="text"  name="spuIds"/>
	      <div id="t-wrap">
		    <table class="summer-datagrid" id="dataList">
			    <thead>
				    <tr>
				        <th>商品名称</th>
				        <th>商品图片</th>
				        <th>商品类型</th>
				        <th>商品价格</th>
				        <th>商品红包</th>
				        <th>商品券后价</th>
				        <th>佣金率</th>
						<th>佣金金额</th>
				        <th>备注</th>
				        <th>操作</th>
				    </tr>
			    </thead>
		    </table>
		</div>
		
	 <div class="form-btn-wrapper" id="funcbar">
        <a class="btn btn-normal" id="backBtn">关闭</a>
    </div>
  </div>
  </div>
	
</form>
<script>
    var  permission = CommonUtil.getPermission('${name_english}');
    $(function () {
    	
    	//初始化上传
   	 $("#img").filePlugin({
   	 	type:'image'
     });
     $("#banner").filePlugin({
    	 type:'image'
     });
	     //初始化下拉选项
	   	 $('#isVisible').combobox({
	           valueField : 'code',
	           textField : 'name',
	           url : COMMON_URL.getCode + '?type=T_DM_T_MARKET_ADVERT_IS_VISIBLE'
	       });
	   	 $('#spuPlatform').combobox({
	         valueField : 'code',
	         textField : 'name',
	         url : COMMON_URL.getCode + '?type=T_DM_T_GOODS_SPU_SPU_PLATFORM'
	     });
	 	 $('#isHot').combobox({
	         valueField : 'code',
	         textField : 'name',
	         url : COMMON_URL.getCode + '?type=T_DM_T_GOODS_SPU_IS_HOT'
	     });
	 	 $('#isJingping').combobox({
	 	        valueField : 'code',
	 	        textField : 'name',
	 	        url : COMMON_URL.getCode + '?type=T_DM_T_GOODS_SPU_IS_JINGPING'
	 	    });
	 	 //T_DM_T_GOODS_SPU_WL_COMMISSION
	 	 $('#wlCommission').combobox({
	         valueField : 'code',
	         textField : 'name',
	         url : COMMON_URL.getCode + '?type=T_DM_WL_COMMISSION'
	     });
	 	 //T_DM_T_GOODS_SPU_WL_COMMISSION_SHARE
	 	 $('#wlCommissionShare').combobox({
	         valueField : 'code',
	         textField : 'name',
	         url : COMMON_URL.getCode + '?type=T_DM_T_GOODS_SPU_WL_COMMISSION_SHARE'
	     });
	 	 //T_DM_T_GOODS_SPU_CREATE_TIME
	 	 $('#createTime').combobox({
	         valueField : 'code',
	         textField : 'name',
	         url : COMMON_URL.getCode + '?type=T_DM_T_GOODS_SPU_CREATE_TIME'
	     });
	 	 
	 	//初始化下拉选项  商品所属公司
	 	 $('#categoryId').combobox({
	         url : CONST_URL.GET_CATEGORY_ID, 
	         valueField : 'id',
	         async:false,
	         textField : 'name'
	     });
	    	
	 	$('#linkType').combobox({
	        valueField : 'code',
	        textField : 'name',
	        url : COMMON_URL.getCode + '?type=T_DM_T_MARKET_LINK_TYPE',
	        onSelect: function(data){
	        	if('h5'==data.code){
	        		
	        		$("#happvalue").remove();
	        		
	        		$("#happ").after('<div id="happvalue" class="form-cont">'+
	        		        '<p class="form-cont-title">H5模板</p>'+
	        		        '<input type="text" id="value" name="value" class="summer-input"/>'+
	        		     '</div>');
	        		$('#value').combobox({
	        	        valueField : 'code',
	        	        textField : 'name',
	        	        url : COMMON_URL.getCode + '?type=T_DM_H5_TEMPLET'
	        	    });
	        	}
				if('app'==data.code){
	        		
	        		$("#happvalue").remove();
	        		
	        		$("#happ").after('<div id="happvalue" class="form-cont">'+
	        		        '<p class="form-cont-title">app模板</p>'+
	        		        '<input type="text" id="value" name="value" class="summer-input"/>'+
	        		     '</div>');
	        		$('#value').combobox({
	        	        valueField : 'code',
	        	        textField : 'name',
	        	        url : COMMON_URL.getCode + '?type=T_DM_APP_TEMPLET'
	        	    });
	        	}
	        }
	    });
	   	
	   	$('#type').combobox({
	        valueField : 'code',
	        textField : 'name',
	        url : COMMON_URL.getCode + '?type=T_DM_T_MARKET_ACTIVITY_TYPE'
	    });
	   
    	//初始化funcbar
     	$('#funcbar').prepend($.funcbar({
            type: 'button',
            data: permission,
            permit: ['${name_english}:add']
        }));
   	     	
    	//保存按钮
    	$('#funcbar').on('click', 'a[data-permit="${name_english}:add"]', {isContinue: false},  submit);
    	
    	//返回按钮
    	$('#backBtn,#goBack').on('click',backMain);
    	
    	// 查询按钮
        $('#search').on('click', reloadTable);
    	
        createTable();
	  	  $('#reset').on('click', function() {
				//重置文本框的值
				$('#goodsName').val('');
				$('#spuPlatform').combobox('clear');
				$('#categoryId').combobox('clear');
				$('#isJingping').combobox('clear');
				$('#isHot').combobox('clear');
				$('#wlCommission').combobox('clear');
				$('#wlCommissionShare').combobox('clear');
				$('#createTime').combobox('clear');
				reloadTable();
			});
    	
    });
    
    
 	// 重新加载表格
	function reloadTable() {
		wlcReorder = $('#wlCommission').combobox('getValue');	
		wlcsReorder = $('#wlCommissionShare').combobox('getValue');
		timeReorder = $('#createTime').combobox('getValue');
		createTable(wlcReorder,wlcsReorder,timeReorder);
		$('#dataList').datagrid('reload', {
			ajax : {
				param : {
					"goodsName": trimSpace($('#goodsName').val()),
					"spuPlatform":$('#spuPlatform').combobox('getValue'),
					"isJingping": $('#isJingping').combobox('getValue'),
					"categoryId":$('#categoryId').combobox('getValue'),
					"isHot":$('#isHot').combobox('getValue')/* ,
					"wlCommission":$('#wlCommission').combobox('getValue'),
					"wlCommissionShare":$('#wlCommissionShare').combobox('getValue'),
					"createTime":$('#createTime').combobox('getValue') */
				}
			}
		});
	}
	
	//创建表格
	function createTable(wlcReorder,wlcsReorder,timeReorder) {
		
		$('#dataList').datagrid({
			ajax : {
				url : CONST_URL.GOODS_LIST+"?wlcReorder="+wlcReorder+"&wlcsReorder="+wlcsReorder+"&timeReorder="+timeReorder,
				param : {	
					"goodsName": trimSpace($('#goodsName').val()),
					 "spuPlatform":$('#spuPlatform').combobox('getValue'),
					"isJingping": $('#isJingping').combobox('getValue'),
					"categoryId":$('#categoryId').combobox('getValue'), 
					"isHot":$('#isHot').combobox('getValue')/* ,
					"wlCommission":$('#wlCommission').combobox('getValue'),
					"wlCommissionShare":$('#wlCommissionShare').combobox('getValue'),
					"createTime":$('#createTime').combobox('getValue') */
				},
				success : function(data) { //成功 
					alert("Data Saved: " + msg);
				}
			},
			columns : [
				{
    		    	 field: 'id',
    		    	 hidden: true
    		     },
    		     {
    		    	 field: 'goodsName'
    		     },
    		     {
    		    	 field: 'mainImageUrl',
    		    	 render: function (rowData) {
    		    		 return '<img style="height:100px;width:100px;" src="'+ rowData.mainImageUrl +'"></img>';
    		    	 }
    		     },
    		     {
    		    	 field: 'spuPlatform'
    		     },
    		     {
    		    	 field: 'price'
    		     },
    		     {
    		    	 field: 'couponMoney'
    		     },
    		     {
    		    	 field:'conPrice'
    		     },
    		     {
    		    	 field:'wlCommissionShare'
    		     },
    		     {
    		    	 field:'wlCommission'
    		     },
    		     {
    		    	 field:'note'
    		     },
					{
						field:'anniu',
	    		    	 render: function (rowData) {
	    		    		 return '<input type="button" class="setHd" value="设置活动"></input>';
	    		    	 }
					}

			]
		});
	}
    
    
 	 //设置活动、取消活动
    $('#t-wrap').on('click', '.setHd', function() {
    	var $this = $(this);
        var id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
        if($(this).val()=="设置活动"){
        	 var ids = $("#spuIds").val();
             ids += ","+id;
             if (ids.substr(0,1)==','){
     			ids=ids.substr(1);
     		 }
             $("#spuIds").val(ids);
             $(this).val("取消活动");
        }else if($(this).val()=="取消活动"){
        	  var ids = $("#spuIds").val();
              var idnew = remove(ids,id)
              $("#spuIds").val(idnew);
              $(this).val("设置活动");
        }
    });
 	 
    //在某个字符串中删除指定字符串
    function remove(a,b){
        var c=a.split(','),d="";
        for(var i=0;i<c.length;i++){
            d+=c[i]==b?"":","+c[i];
        }
        return d.length>0?d.substring(1):"";
    }
    
    
    //表单提交
    function submit(event) {
         $("#addForm").form({
        	 buttons : ['#saveBtn','#saveBtnContinue'],
             ajax: {
                 url: CONST_URL.ADD
             },
             onSubmitSuccess: function (data) {
            	 $.stip({
  	                type:'ok',//显示类型 有info、 ok、 danger
  	                text: '保存成功！',
  	                onBeforeHide: function () {
  	            	  var isContinue = event.data.isContinue;
                   	  if (isContinue) {
                          resetForm();
                   	  } else {
                   		  backMain();
                   	  }
  	               }
              	});
              }
         }).form("submit");
    }
    
    //保存并继续清空form
    function resetForm(){
        //$('#xm,#zw,#cs,#bgdh,#sjhm').val('');
    }
    
    //返回主页面
    function backMain() {
    	window.location.href = CONST_URL.INIT_MAIN;
    }
    
   
    //请求url
    var CONST_URL = {
    	LIST: basePath + "/mall/system/goods/goodsspu/list",
    	INIT_MAIN: basePath + "${common_url}init",
    	GET_CATEGORY_ID: basePath + '/mall/system/market/marketshare/getGoodsCategory',
    	GOODS_LIST: basePath + '/mall/system/market/marketshare/goodsList',
       	ADD: basePath + "${common_url}add"
    };
    
</script>
</body>
</html>